package com.grace.cms.search.lucene.document;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.document.StringField;

/**
 * 标签文档实体类
 */
public class TagDocument implements SearchableDocument {
    
    public static final String ID = "id";
    public static final String NAME = "name";
    public static final String DESCRIPTION = "description";
    public static final String TYPE = "type";
    
    private String id;
    private String name;
    private String description;
    
    public TagDocument() {}
    
    public TagDocument(String id, String name, String description) {
        this.id = id;
        this.name = name;
        this.description = description;
    }
    
    /**
     * 将TagDocument转换为Lucene Document
     * @return Document
     */
    public Document toDocument() {
        Document document = new Document();
        document.add(new StringField(ID, id, Field.Store.YES));
        document.add(new TextField(NAME, name, Field.Store.YES));
        document.add(new TextField(DESCRIPTION, description, Field.Store.YES));
        document.add(new StringField(TYPE, "tag", Field.Store.YES)); // 添加文档类型标识
        return document;
    }
    
    /**
     * 从Lucene Document转换为TagDocument
     * @param document Lucene Document
     * @return TagDocument
     */
    public static TagDocument fromDocument(Document document) {
        return new TagDocument(
            document.get(ID),
            document.get(NAME),
            document.get(DESCRIPTION)
        );
    }
    
    // Getters and Setters
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
}